#include <stdio.h>
#include <stdlib.h>

typedef int ElemType;


/*二分查找*/
//定义顺序查找表
typedef struct {
    ElemType* data;
    int tabLen;
} SSTable;

SSTable * init(int * data){
    SSTable *L = (SSTable *) malloc(sizeof(SSTable));;
    L->data = data;
    L->tabLen = sizeof(data);

    return L;
}

// 二分查找
int bin_search(SSTable L,ElemType e){
    int max = L.tabLen;
    int min = 0;
    int mid = (max + min) / 2;
    while(min <= max){
        if(e == L.data[mid])
            return mid;
        if(e > L.data[mid]){
            min = mid + 1;
        } else{
            max = mid - 1;
        }
        mid = (max + min)/2;
    }
    return -1;
}



int main(void) {

    int data [] = {1,2,3,4,5};
    SSTable * table = init(data);

    int res = bin_search(*table,3);

    printf("%d\n",res);

    return 0;
}